home *** CD-ROM | disk | FTP | other *** search
- #include "GetAttribute.h"
-
-
- OSErr GetAttributeFromRID (RecordIDPtr rid, const AttributeTypePtr attrType,
- AttributePtr *theAttribute, AuthIdentity identity)
- {
- OSErr err;
- RecordIDPtr recordList[1];
- AttributeTypePtr attTypeList[1];
- DirParamBlock pb;
-
-
- recordList[0] = rid;
- attTypeList[0] = attrType;
-
- pb.lookupGetPB.ioCompletion = nil;
- pb.lookupGetPB.serverHint.aNet = 0;
- pb.lookupGetPB.serverHint.aNode = 0;
- pb.lookupGetPB.serverHint.aSocket = 0;
- pb.lookupGetPB.dsRefNum = 0;
- pb.lookupGetPB.identity = identity;
- pb.lookupGetPB.clientData = 0L;
- pb.lookupGetPB.aRecordList = recordList;
- pb.lookupGetPB.attrTypeList = attTypeList;
- pb.lookupGetPB.recordIDCount = 1;
- pb.lookupGetPB.attrTypeCount = 1;
- pb.lookupGetPB.includeStartingPoint = TRUE;
- pb.lookupGetPB.getBuffer = NewPtr(kBufSize);
- if ((err = MemError()) != noErr)
- return err;
- pb.lookupGetPB.getBufferSize = kBufSize;
- pb.lookupGetPB.startingRecordIndex = 1;
- pb.lookupGetPB.startingAttrTypeIndex = 1;
- pb.lookupGetPB.startingAttribute.cid.source = 0L;
- pb.lookupGetPB.startingAttribute.cid.seq = 0L;
-
-
- if ((err = DirLookupGet (&pb, FALSE)) == noErr)
- {
- *theAttribute = (AttributePtr) -1;
- pb.lookupParsePB.ioCompletion = nil;
- pb.lookupParsePB.serverHint.aNet = 0;
- pb.lookupParsePB.serverHint.aNode = 0;
- pb.lookupParsePB.serverHint.aSocket = 0;
- pb.lookupParsePB.dsRefNum = 0;
- pb.lookupParsePB.identity = identity;
- pb.lookupParsePB.clientData = (long) theAttribute;
- pb.lookupParsePB.aRecordList = recordList;
- pb.lookupParsePB.attrTypeList = attTypeList;
- pb.lookupParsePB.eachRecordID = myForEachLookupRecordID;
- pb.lookupParsePB.eachAttrType = myForEachAttrTypeLookup;
- pb.lookupParsePB.eachAttrValue = myForEachAttrValue;
- pb.lookupParsePB.recordIDCount = 1;
- pb.lookupParsePB.attrTypeCount = 1;
- pb.lookupParsePB.getBuffer = pb.lookupGetPB.getBuffer;
- pb.lookupParsePB.getBufferSize = pb.lookupGetPB.getBufferSize;
- err = DirLookupParse (&pb, FALSE);
- if (err == noErr && *theAttribute == nil)
- err = memFullErr;
-
- if (*theAttribute == (AttributePtr) -1)
- {
- err = kOCENoSuchAttributeType;
- *theAttribute = nil;
- }
- }
-
- if (pb.lookupGetPB.getBuffer != nil)
- DisposePtr (pb.lookupGetPB.getBuffer);
-
- return (err);
- }
-
- static pascal Boolean myForEachLookupRecordID (long clientData, const RecordID *recordID)
- {
- #pragma unused (clientData,recordID)
-
- return (FALSE);
- }
-
- static pascal Boolean myForEachAttrTypeLookup (long clientData,
- const AttributeType *attrType, AccessMask myAttrAccMask)
- {
- #pragma unused (clientData,attrType,myAttrAccMask)
-
- return (FALSE);
- }
-
- static pascal Boolean myForEachAttrValue (long clientData, const Attribute *attribute)
- {
- AttributePtr *theAttribute;
-
- theAttribute = (AttributePtr *) clientData;
- if ((*theAttribute = (AttributePtr)NewPtr (sizeof (Attribute))) != nil)
- {
- BlockMove((Ptr) attribute, *theAttribute,sizeof (Attribute));
- if (((**theAttribute).value.bytes = NewPtr ((*attribute).value.dataLength)) != nil)
- BlockMove((*attribute).value.bytes,(**theAttribute).value.bytes,(*attribute).value.dataLength);
- else
- {
- DisposePtr ((Ptr)*theAttribute);
- *theAttribute = nil;
- }
- }
-
- return (TRUE);
- }